import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import centerrouter from './routes/center'
import cinemarouter from './routes/cinema'
import filmrouter from './routes/film'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
   
    redirect:'/film'
  },
  {
    path: '/filmdetail/:filmid',
    name:'filmdetail',
    component:()=>import('@/views/Detail/Detail.vue')
  },
  {
    path: '/vuex',
  
    component:()=>import('@/views/vuex/Vuex.vue')
  },
  {
    path:'/city',
    name:'city',
    component:()=>import('@/views/City/City.vue')
  }, 
  {
    path:'/register',
    name:'register',
    component:()=>import('@/views/register/register.vue')
  },
  {
    path:'/login',
    name:'login',
    component:()=>import('@/views/login/login.vue')
  },
  centerrouter,
  cinemarouter,
  filmrouter
  
  
]

const router = new VueRouter({
  routes
})


// 路由守卫  
router.beforeEach((to,from ,next)=>{
  // 这里面 vip页面 或者登录后才能去的页面
  let arr = [
      '/cinema'
  ]
  // /center

  if(!arr.includes(to.path)) {
    // 如果不是去vip页面 或者登陆后才能去的页面 直接next放行
     next()
  }else {
    // 如果要去vip 或者登录才能进去的页面 需要判断
    if(localStorage.getItem('_token')) {
      next()
    }else {
      next({path:'/login'})
    }
  }

})

export default router
